home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / misc / football / user / updateschedulescores.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-29  |  14KB  |  533 lines

  1. /* Mode=Run */
  2. /* ***********************************************************************
  3.  
  4.   UPDATE SCHEDULE FILE PROGRAM FOR FOOTBALL REXX SUITE
  5.   ----------------------------------------------------
  6.                    Copyright  Mark Naughton 1998
  7.  
  8.  
  9. Version    Date     History
  10. --------------------------------------------------------------------------
  11.  
  12.  1.0       011098   Created. Found problem where the updates are not
  13.                     successfully made - fixed. Updated messages.
  14.  1.1       050599   Added code to check the schedule file to see if it
  15.                     contains the right number of matches for the number of
  16.                     teams playing a specified number of times. Added
  17.                     support for playing an odd number of times and for
  18.                     schedules for teams playing more than twice.
  19.            250899   Added error msg for file check.
  20.            050999   Converted to use locale. Some error messages, before
  21.                     reading the locale, will still be in English.
  22.                     Converted to use a global date format file.
  23.            190999   Changed schedule directory.
  24.  
  25. **************************************************************************
  26.  
  27. Procedure
  28. ---------
  29.  
  30. 1. Check files exist. Get schedule definition filename from '.df' file.
  31. 2. Read specified schedule definition file. Check schedule contains the
  32.    right number of matches before proceeding.
  33. 3. Read schedules and store dates/weeks.
  34. 4. Give error if the number of teams does not equal the number of lines in
  35.    the schedule file.
  36. 5. Write the dates/weeks to a file then use an external program to sort
  37.    them, writing back to the file.
  38. 6. Read dates into array and delete file.
  39. 7. Format dates array with season start date.
  40. 8. Format and write '.sf' files.
  41. 9. Read all data from Learn (without '*') into an array. Close file.
  42. 10.Open Schedule file and read into an array. Close file.
  43. 11.Update Schedule array with data from Learn but only if a match hasn't
  44.    been played.
  45. 12.Write to Schedule file. Close file. Exit.
  46.  
  47. ************************************************************************** */
  48. PARSE ARG league_file
  49.  
  50. version      = 1
  51. league_file  = "Data/" || strip(league_file)
  52. input_file   = '.df'
  53. input2_file  = '.schd'
  54. input3_file  = '.sflearn'
  55. output_file  = '.sf'
  56. title        = '*LEAGUE_NAME='
  57. autosched    = "*AUTOSCHD="
  58. playother    = '*PLAY_OTHER='
  59. teams.       = '???'
  60. dateweeks.   = '???'
  61. tdateweeks.  = '???'
  62. schedules2.  = '???'
  63. schedules4.  = '???'
  64. schedules6.  = '???'
  65. schedules8.  = '???'
  66. schedules0.  = '???'
  67. selines.     = '???'
  68. sdlines.     = '???'
  69. autos        = 0
  70. tcount       = 0
  71. ttc          = 0
  72. separator    = '*'
  73. not_played   = '__   __'
  74. refdays      = "Sunday Monday Tuesday Wednesday Thursday Friday Saturday" /* used for word positions */
  75.  
  76.  
  77.  
  78. if open(datafile,"Data/Football.locale",'r') then do
  79.    line = readln(datafile)
  80.    locdir = strip(line)
  81.    close(datafile)
  82. end
  83. else do
  84.    say
  85.    say "ERROR :    (UpdateScheduleScores)"
  86.    say
  87.    say "Cannot read 'Data/Football.locale' for the locale settings."
  88.    exit
  89. end
  90.  
  91. dfordir = locdir"Football.locale_data"
  92. locdir  = locdir"User/UpdateScheduleScores.data"
  93.  
  94. if open(datafile,"ENV:FootballRXPath",'r') then do
  95.    line = readln(datafile)
  96.    rxdir = strip(line)
  97.    close(datafile)
  98. end
  99. else
  100.    rxdir = "SYS:Rexxc/"
  101.  
  102. if exists(locdir) > 0 then do
  103.   address command rxdir'rx 'locdir
  104.   VarCount = getclip('VarCount')
  105.   do i = 1 to VarCount
  106.     interpret getclip('var.'i)
  107.   end
  108. end
  109. else do
  110.    say
  111.    say "ERROR :    (UpdateScheduleScores)"
  112.    say
  113.    say "Cannot find '"locdir"' to read locale settings."
  114.    exit
  115. end
  116.  
  117. if exists(dfordir) > 0 then do
  118.   address command rxdir'rx 'dfordir
  119.   VarCount = getclip('VarCount')
  120.   do i = 1 to VarCount
  121.     interpret getclip('var.'i)
  122.   end
  123. end
  124. else do
  125.    say
  126.    say "ERROR :    (UpdateScheduleScores)"
  127.    say
  128.    say "Cannot find '"dfordir"' to read date locale settings."
  129.    exit
  130. end
  131.  
  132.  
  133. if exists(league_file || input_file) = 0 then do
  134.    say
  135.    say uss_error
  136.    say
  137.    say uss_t1"'"league_file || input_file"'."
  138.    exit
  139. end
  140.  
  141. tcount = 0
  142. if open(datafile,league_file || input_file,'r') then do
  143.    do while ~eof(datafile)
  144.       line = readln(datafile)
  145.       line = strip(line)
  146.       if pos(separator,line) > 0 then do
  147.          if pos(autosched,line) > 0 then do
  148.             autofile = delstr(line,1,10)
  149.             autos = 1
  150.          end
  151.          if pos(title,line) > 0 then do
  152.             parse var line "*LEAGUE_NAME=" league_title
  153.             league_title = strip(league_title)
  154.          end
  155.          if pos(playother,line) > 0 then
  156.             playo = delstr(line,1,12)
  157.  
  158.        end
  159.        if pos(separator,line) = 0 & line ~="" then do
  160.             tcount = tcount + 1
  161.             teams.tcount = line
  162.        end
  163.    end
  164.    close(datafile)
  165. end
  166. else do
  167.    say
  168.    say uss_error
  169.    say
  170.    say uss_t3"'"league_file || input_file"'"uss_t5
  171.    exit
  172. end
  173.                                           /* Automatic Schedule creation */
  174. if autos = 1 then do
  175.  
  176.    if exists("Data/Schedules/"autofile||input2_file) = 0 then do
  177.       say
  178.       say uss_error
  179.       say
  180.       say uss_t1"'Data/Schedules/"autofile||input2_file"'."
  181.       exit
  182.    end
  183.  
  184.    ct = 0
  185.    sct2= 0
  186.    sct4= 0
  187.    sct6= 0
  188.    sct8= 0
  189.    sct0= 0
  190.    weeks = 0
  191.    dates = 0
  192.    sch = 1
  193.  
  194.  
  195.    if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do
  196.       mkct = ((tcount - 1) * playo) * (tcount/2)
  197.       kmct = 0
  198.       do while ~eof(datafile)
  199.          line = readln(datafile)
  200.          if line ~= '' & pos(separator,line) = 0 then do
  201.             counter = words(line)
  202.             do i=1 to counter
  203.                if word(line,i) ~= 0 then
  204.                   kmct = kmct + 1
  205.             end
  206.          end
  207.       end
  208.       close(datafile)
  209.    end
  210.    else do
  211.       say
  212.       say uss_error
  213.       say
  214.       say uss_t1"'Data/Schedules/"autofile||input2_file"'"uss_t5
  215.       say
  216.       say
  217.       say uss_t6", '"league_file || input_file"' "uss_t7
  218.       exit
  219.    end
  220.    if mkct ~= kmct then do
  221.       say
  222.       say uss_error
  223.       say
  224.       say uss_t8" 'Data/Schedules/"autofile||input2_file"'"
  225.       say uss_t9" "tcount" "uss_t10
  226.       say playo" "uss_t11" "kmct" "uss_t12" "mkct" "uss_t13
  227.       say uss_t14
  228.       say uss_t15
  229.       exit
  230.    end
  231.  
  232.    if open(datafile,"Data/Schedules/"autofile||input2_file,'r') then do
  233.       do while ~eof(datafile)
  234.          line = readln(datafile)
  235.          if pos("*WEEKS",line) then do
  236.             weeks=1
  237.          end
  238.          if pos("*DATES=",line) then do
  239.             startdate=substr(line,8,8)
  240.             dates = 1
  241.          end
  242.          if pos("*NEXT",line) > 0 then sch = sch + 1
  243.          if line ~= '' & pos(separator,line) = 0 then do
  244.             if sch = 1 then do
  245.                sct2 = sct2 + 1
  246.                schedules2.sct2 = line
  247.             end
  248.             if sch = 2 then do
  249.                sct4 = sct4 + 1
  250.                schedules4.sct4 = line
  251.             end
  252.             if sch = 3 then do
  253.                sct6 = sct6 + 1
  254.                schedules6.sct6 = line
  255.             end
  256.             if sch = 4 then do
  257.                sct8 = sct8 + 1
  258.                schedules8.sct8 = line
  259.             end
  260.             if sch = 5 then do
  261.                sct0 = sct0 + 1
  262.                schedules0.sct0 = line
  263.             end
  264.             counter = words(line)
  265.             do i=1 to counter
  266.                sdate = word(line,i)
  267.                if sdate = 0 then
  268.                   iterate
  269.                if ct = 0 then do
  270.                   ct = ct + 1
  271.                   dateweeks.ct = sdate
  272.                end
  273.                else do
  274.                   ij = 0
  275.                   do j=1 to ct
  276.                      if sdate = dateweeks.j then do
  277.                         ij = 1
  278.                         leave
  279.                      end
  280.                   end
  281.                   if ij = 0 then do
  282.                      ct = ct + 1
  283.                      dateweeks.ct = sdate
  284.                   end
  285.                end
  286.             end
  287.          end
  288.       end
  289.       close(datafile)
  290.    end
  291.    else do
  292.       say
  293.       say uss_error
  294.       say
  295.       say uss_t1"'Data/Schedules/"autofile||input2_file"'"uss_t5
  296.       exit
  297.    end
  298.    sct = (sct2 + sct4 + sct6 + sct8 + sct0) / sch
  299.  
  300.    if counter ~= sct then do
  301.       say
  302.       say uss_error
  303.       say
  304.       say uss_t16" "sct" "uss_t17
  305.       say uss_t18" "tcount" "uss_t19
  306.       say
  307.       say uss_t20
  308.       say
  309.       say uss_t21"  "league_file||input_file
  310.       say uss_t22"  Data/Schedules/"autofile||input2_file
  311.       say
  312.       exit
  313.    end
  314.  
  315.    if open(datafile2,"RAM:schd.temp",'w') then do
  316.       do j=1 to ct
  317.          writeln(datafile2,dateweeks.j)
  318.       end
  319.       close(datafile2)
  320.    end
  321.    else do
  322.       say
  323.       say uss_error
  324.       say
  325.       say uss_t23
  326.       exit
  327.    end
  328.  
  329.    if weeks = 1 then
  330.       address command 'sort RAM:schd.temp RAM:schd.temp'
  331.    if dates = 1 then
  332.       address command 'Exec/SortWkDts'
  333.  
  334.    if open(datafile2,"RAM:schd.temp",'r') then do
  335.       do j=1 to ct
  336.          dateweeks.j = readln(datafile2)
  337.       end
  338.       close(datafile2)
  339.    end
  340.    else do
  341.       say
  342.       say uss_error
  343.       say
  344.       say uss_t24
  345.       exit
  346.    end
  347.  
  348.    address command 'delete >NIL: RAM:schd.temp'
  349.  
  350.    if dates = 1 then do
  351.       do j=1 to ct
  352.          if dateweeks.j = startdate then do
  353.             do i=1 to j-1
  354.                tdateweeks.i = dateweeks.i
  355.             end
  356.             k = 1
  357.             do i=j to ct
  358.                dateweeks.k = dateweeks.i
  359.                k = k + 1
  360.             end
  361.             do i=1 to j-1
  362.                dateweeks.k = tdateweeks.i
  363.                k = k + 1
  364.             end
  365.             leave
  366.          end
  367.       end
  368.    end
  369.  
  370.    if open(outfile,league_file || output_file,"w") then do
  371.       writeln(outfile,"*")
  372.       writeln(outfile,"**" league_title)
  373.       writeln(outfile,"*")
  374.       writeln(outfile,"*")
  375.  
  376.       matches = 0
  377.       do i=1 to ct
  378.          if weeks = 1 then
  379.             writeln(outfile,"*Week: "dateweeks.i)
  380.  
  381.          if dates = 1 then do
  382.             mnth = substr(dateweeks.i,3,2)
  383.             ndate= substr(dateweeks.i,5,4)||mnth||substr(dateweeks.i,1,2)
  384.             weekd= date('w',ndate,'s')
  385.             do kw=1 to 7
  386.                if weekd = word(refdays,kw) then do
  387.                   weekd = word(days,kw)
  388.                   leave
  389.                end
  390.             end
  391.             parse var date_format "day" sp1 "number" sp2 "month" sp3 "year" .
  392. /* DATE */
  393.             writeln(outfile,"*Date: "weekd||sp1||substr(dateweeks.i,1,2)||sp2||word(months,mnth)||sp3||substr(dateweeks.i,5,4))
  394.          end
  395.          writeln(outfile,"*")
  396.          do k=1 to counter
  397.             do j=1 to counter
  398.                do l=1 to sch
  399.                   if l=1 then sdate = word(schedules2.k,j)
  400.                   if l=2 then sdate = word(schedules4.k,j)
  401.                   if l=3 then sdate = word(schedules6.k,j)
  402.                   if l=4 then sdate = word(schedules8.k,j)
  403.                   if l=5 then sdate = word(schedules0.k,j)
  404.                   if dateweeks.i = sdate then do
  405.                      writech(outfile,left(teams.k,30))
  406.                      writeln(outfile," __   __ " teams.j)
  407.                      matches = matches + 1
  408.                      leave
  409.                   end
  410.                end
  411.             end
  412.          end
  413.          writeln(outfile,"*")
  414.       end
  415.       writeln(outfile,"*")
  416.       close(outfile)
  417.    end
  418.    else do
  419.       say
  420.       say uss_error
  421.       say
  422.       say uss_t2"'"league_file || output_file"'."
  423.       exit
  424.    end
  425. end
  426. else do
  427.    say
  428.    say uss_error
  429.    say
  430.    say uss_t6", "league_file||input_file", "uss_t25
  431.    say uss_t26
  432.    say uss_t27
  433.    say
  434.    exit
  435. end
  436.  
  437. secount = 0
  438. if open(datafile,league_file||input3_file,'r') then do
  439.    do while ~eof(datafile)
  440.       line = readln(datafile)
  441.       line = strip(line)
  442.       if pos(separator,line) = 0 & line ~= "" then do
  443.          secount         = secount + 1
  444.          selines.secount = line
  445.       end
  446.    end
  447.    close(datafile)
  448. end
  449. else do
  450.    say
  451.    say uss_error
  452.    say
  453.    say uss_t3"'"league_file||input3_file"'"uss_t5
  454.    exit
  455. end
  456.  
  457. sdcount = 0
  458. if open(datafile3,league_file || output_file,'r') then do
  459.    do while ~eof(datafile3)
  460.        line = readln(datafile3)
  461.        line = strip(line)
  462.        if line ~= "" then do
  463.           sdcount         = sdcount + 1
  464.           sdlines.sdcount = line
  465.        end
  466.    end
  467.    close(datafile3)
  468. end
  469. else do
  470.    say
  471.    say uss_error
  472.    say
  473.    say uss_t3"'"league_file || output_file"'"uss_t5
  474.    exit
  475. end
  476.  
  477. i    = 0
  478. done = 0
  479.  
  480. do i=1 to secount
  481.    shome = strip(substr(selines.i,1,30))
  482.    saway = strip(substr(selines.i,41,30))
  483.    do j=1 to sdcount
  484.       home  = strip(substr(sdlines.j,1,30))
  485.       away  = strip(substr(sdlines.j,41,30))
  486.       if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do
  487.          sdlines.j = selines.i
  488.          leave
  489.       end
  490.    end
  491. end
  492.  
  493.  
  494. /*
  495. do j=1 to sdcount
  496.    shome = strip(substr(sdlines.j,1,30))
  497.    saway = strip(substr(sdlines.j,41,30))
  498.    do i=1 to secount
  499.       home  = strip(substr(selines.i,1,30))
  500.       away  = strip(substr(selines.i,41,30))
  501.       if shome = home & saway = away & pos(not_played,sdlines.j) > 0 then do
  502.          sdlines.j = selines.i
  503.          k = k + 1
  504.          leave
  505.       end
  506.    end
  507.    if k = secount then leave
  508. end
  509. */
  510.  
  511. if open(datafile3,league_file || output_file,'w') then do
  512.    do j=1 to sdcount
  513.       writeln(datafile3,sdlines.j)
  514.    end
  515.    close(datafile3)
  516. end
  517. else do
  518.    say
  519.    say uss_error
  520.    say
  521.    say uss_t3"'"league_file || output_file"'"uss_t4
  522.    exit
  523. end
  524.  
  525. say
  526. say uss_t28
  527. say
  528. say uss_t29
  529. say "'Data/Schedules/"autofile||input2_file"' "uss_t30" '"league_file||input3_file"'"
  530. say uss_t31" '"league_file||output_file"'."
  531. say
  532.  
  533. exit